#include "stm32f10x.h"
#include "stdint.h"
#include "fonts.h"

typedef enum
{
  ILI_9325_OK,
  ILI_9325_NOK
}ILI_9325_STATUS;


#define Bank1_LCD_D    ((uint32_t)0x60020000)    
#define Bank1_LCD_C    ((uint32_t)0x60000000)   

#define LCD_BackLightOn() GPIO_SetBits(GPIOD, GPIO_Pin_13) 

#define LCD_COLOR_WHITE          0xFFFF
#define LCD_COLOR_BLACK          0x0000
#define LCD_COLOR_GREY           0xF7DE
#define LCD_COLOR_BLUE           0x001F
#define LCD_COLOR_BLUE2          0x051F
#define LCD_COLOR_BLUE3          0xF6FF
#define LCD_COLOR_RED            0xF800
#define LCD_COLOR_MAGENTA        0xF81F
#define LCD_COLOR_GREEN          0x07E0
#define LCD_COLOR_GREEN2         0xFF26
#define LCD_COLOR_CYAN           0x7FFF
#define LCD_COLOR_YELLOW         0xFFE0

#define LCD_DEFAULT_FONT         Font16x24

void ILI9325_Init(void);

/**    
  * @brief  Write LCD index register
  * @param  index value    
  * @retval None    
  */ 
void ILI9325_WriteIR(uint16_t index);

void ILI9325_SetRegister(unsigned int index,unsigned int val);

/**    
  * @brief  Write LCD data register
  * @param  data value   
  * @retval None    
  */
void ILI9325_WriteWDR(uint16_t val);

/**    
  * @brief  Read data register value
  * @param  None   
  * @retval Data register value    
  */
uint16_t ILI9325_ReadRDR(void);

#define ILI9325_GRAMOperation() ILI9325_WriteIR(0x22)
#define ILI9325_WritePixel(x) ILI9325_WriteWDR(x)

#define ILI9325_VerticalScreen() ILI9325_SetRegister(0x0003,0x1030)
#define ILI9325_HorizontalScreen() ILI9325_SetRegister(0x0003,0x1038)
#define ILI9325_ZoomInByTwo() ILI9325_SetRegister(0x0004, 0x0001)
#define ILI9325_ZoomInByFour() ILI9325_SetRegister(0x0004, 0x0003)

/**    
  * @brief  Draw windows area
  * @param  None  
  * @retval None  
  */
void ILI9325_DrawWindowArea(uint16_t startX, 
                            uint16_t startY, 
                            uint16_t width, 
                            uint16_t height, 
                            uint16_t pixels[]);
                                                                                                            
/**    
  * @brief  Fill windows area with color
  * @param  None  
  * @retval None  
  */
void ILI9325_FillWindowArea(uint16_t startX,
                            uint16_t startY,
                            uint16_t width,
                            uint16_t height,
                            uint16_t color);
                            
/**    
  * @brief  Set cursor position
  * @param  X position, Y position 
  * @retval None  
  */
void ILI9325_SetCursorPos(uint16_t x ,uint16_t y);

void ILI9325_SetFont(sFONT *fonts);
void ILI9325_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c);
void ILI9325_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii);
void ILI9325_DisplayStringLine(uint8_t Line, char *ptr);

/**    
  * @brief  Display color bitmap on screen in RGB 565
  *         bitmap file is stored in SDcard
  * @param  Line poistion, string to be display 
  * @retval None  
  */
uint8_t LCD_WriteBMP(uint16_t Xpos, uint16_t Ypos, char *fileName, uint8_t direction);
void ILI9325_DrawMonoPict(const char *Pict);
void ILI9325_DrowProgessBar(uint16_t startX,uint16_t startY, uint16_t width,uint16_t height,uint16_t color);
void ILI9325_DrowLine(uint16_t x0,uint16_t y0, uint16_t x1,uint16_t y1,uint16_t color);
void ILI9325_Clear();
void ILI9325_SetBackColor(uint16_t color);
void ILI9325_DrowPoint(uint16_t x, uint16_t y, uint16_t color);
void ILI9325_DrowBigPoint(uint16_t x, uint16_t y, uint16_t color);